import React, { useContext, useRef, useState } from 'react';

import { Cascader, DatePicker, Input, message, Radio, Select, Typography } from 'antd';
import moment from 'moment';
import PropTypes from 'prop-types';
import { useDeepCompareEffect } from 'react-use';

import CityPicker from '@/components/CityPicker';
import { defaultFormatResult, useDictionary, useRequest } from '@/hooks';
import EmployeeDetailContext from '@/pages/Organization/EmployeeManage/EmployeeDetail/store/context';
import { getEmployeeFieldConfig } from '@/pages/Organization/EmployeeManage/services';

import FormContainer, { FormItem } from './FormContainer';
import { parseEmployeeExtendInfoList } from './util';

const { Text } = Typography;

// 户籍类型字典
export const HOUSEHOLD_TYPE_MAP = {
    HouseholdType1_local: [
        {
            code: 'household2',
            value: 'HouseholdType2_town',
            text: '城镇'
        },
        {
            code: 'household2',
            value: 'HouseholdType2_village',
            text: '农村'
        }
    ],
    HouseholdType1_outland: [
        {
            code: 'household2-2',
            value: 'HouseholdType2_town_inner',
            text: '城镇（省内）'
        },
        {
            code: 'household2-2',
            value: 'HouseholdType2_village_inner',
            text: '农村（省内）'
        },
        {
            code: 'household2-2',
            value: 'HouseholdType2_town_outter',
            text: '城镇（省外）'
        },
        {
            code: 'household2-2',
            value: 'HouseholdType2_village_outter',
            text: '农村（省外）'
        }
    ]
};

// 户籍类型选项
export const CENSUS_REGISTER_OPTIONS = [
    {
        value: 'HouseholdType1_local',
        label: '本地',
        children: [
            {
                value: 'HouseholdType2_town',
                label: '城镇'
            },
            {
                value: 'HouseholdType2_village',
                label: '农村'
            }
        ]
    },
    {
        value: 'HouseholdType1_outland',
        label: '外地',
        children: [
            {
                value: 'HouseholdType2_town_inner',
                label: '城镇（省内）'
            },
            {
                value: 'HouseholdType2_village_inner',
                label: '农村（省内）'
            },
            {
                value: 'HouseholdType2_town_outter',
                label: '城镇（省外）'
            },
            {
                value: 'HouseholdType2_village_outter',
                label: '农村（省外）'
            }
        ]
    }
];

// 国籍/籍贯预处理
const restoreArrayLinkString = data => (!data ? [] : data.split(','));

/**
 * 员工档案 - 个人信息
 */
const PersonalInfoSection = ({ formData, onChange, readonly, saveAction }) => {
    const formRef = useRef();
    const employeeDetailContext = useContext(EmployeeDetailContext);
    const currentEmployeeCountryCode = employeeDetailContext?.employeeInfo?.countryNameCode;
    const refreshSingaporeIdType = employeeDetailContext?.refreshSingaporeIdType; // 新加坡的身份类型有联动需求, 保存后要手动更新
    // 字典数据
    const [sexTypeList, getSexTypeText] = useDictionary('sexType');
    const [idCardTypeList, getIdCardTypeText] = useDictionary('idCardType');
    const [singaporeIdTypeList, getSingaporeIdTypeText] = useDictionary('singaporeIdType');
    const [singaporeRaceList, getSingaporeRaceText] = useDictionary('singaporeRace');
    const [politicalLandscapeList, getPoliticalLandscapeText] = useDictionary('politicalLandscape');
    const [religionList, getReligionText] = useDictionary('religion');
    const [peopleNationalList, getPeopleNationalListText] = useDictionary('peopleNational');

    // 是否显示户籍类型, 只用国籍是中国的才显示
    const [showHousehold, setShowHousehold] = useState(false);
    // 户籍类型
    const [firstHouseholdType, setFirstHouseholdType] = useState(undefined);
    const [secondHouseholdType, setSecondHouseholdType] = useState(undefined);
    const handleOnHouseHoldChange = record => {
        setShowHousehold(record[0] === '中国');
    };

    // 因为国际化的字段是在 employeeExtendInfoList 数组里面, 这里将它打散到 formData 里面
    const [parsedFormData, setParsedFormData] = useState();
    // 获取国际化字段的默认配置
    const { data: employeeFieldConfig } = useRequest(
        () => getEmployeeFieldConfig({ countryNameCode: currentEmployeeCountryCode, groupCode: 'basic' }),
        {
            ready: !!currentEmployeeCountryCode,
            ...defaultFormatResult
        }
    );

    // mounted
    useDeepCompareEffect(() => {
        // 处理国际化字段
        const employeeExtendInfoMap = parseEmployeeExtendInfoList(
            formData?.employeeExtendInfoList ?? [],
            currentEmployeeCountryCode
        );
        const combineData = { ...formData, ...employeeExtendInfoMap };
        setParsedFormData(combineData);

        // 特殊字段处理
        if (currentEmployeeCountryCode === 'CN') {
            // 判断是否显示户籍类型
            handleOnHouseHoldChange([combineData?.nation]);
            setFirstHouseholdType(combineData?.firstHouseholdType);
            setSecondHouseholdType(combineData?.secondHouseholdType);
        }
    }, [formData, currentEmployeeCountryCode]);

    // 提交
    const { run: submitRun } = useRequest(submitData => saveAction && saveAction(submitData), {
        manual: true
    });
    // 保存
    const handleSubmit = async values => {
        // 扩展字段处理
        const employeeExtendInfoList = employeeFieldConfig?.map(item => {
            let fieldValue = values[item.fieldCode];
            // 数据格式转换
            if (['nationalArea', 'birthplace'].indexOf(item.fieldCode) > -1) {
                fieldValue = fieldValue?.join(',');
            }
            if (['idCardExpiredDate', 'prAcquisitionDate'].indexOf(item.fieldCode) > -1) {
                fieldValue = moment(fieldValue).format('YYYY-MM-DD');
            }
            if (['firstHouseholdType'].indexOf(item.fieldCode) > -1) {
                fieldValue = values.firstHouseholdType?.[0] || '';
            }
            if (['secondHouseholdType'].indexOf(item.fieldCode) > -1) {
                fieldValue = values.firstHouseholdType?.[1] || '';
            }
            return { ...item, fieldValue };
        });
        const submitData = Object.assign({
            employeeCode: parsedFormData.employeeCode,
            nation: values.nation?.join(','),
            birthday: moment(values?.birthday).format('YYYY-MM-DD'),
            employeeName: values.employeeName,
            employeeEnglishName: values.employeeEnglishName,
            sex: values.sex,
            workStartDate: moment(values.workStartDate).format('YYYY-MM-DD'),
            workYears: values.workYears,
            employeeExtendInfoList
        });
        // 表单值预处理
        if (values?.birthday) {
            submitData.age = moment(new Date()).diff(moment(values.birthday), 'year');
        }
        // 提交
        const res = await submitRun(submitData);
        if (res.code === 10000) {
            message.success(res.msg);
            onChange(submitData);
            if (currentEmployeeCountryCode === 'SG') {
                await refreshSingaporeIdType();
            }
        } else {
            message.error(res.msg);
        }
    };

    const handleBeforeCancel = () => {
        const employeeExtendInfoMap = parseEmployeeExtendInfoList(
            formData?.employeeExtendInfoList ?? [],
            currentEmployeeCountryCode
        );
        const combineData = { ...formData, ...employeeExtendInfoMap };

        if (currentEmployeeCountryCode === 'CN') {
            handleOnHouseHoldChange([combineData?.nation]);
        }
        return true;
    };

    const getFormItemValue = (field, defaultValue = undefined) =>
        formRef.current?.form?.getFieldValue(field) || parsedFormData?.[field]?.toString() || defaultValue;

    // render
    return (
        <FormContainer
            wrappedComponentRef={formRef}
            title="基本信息"
            hasEditAuth={!readonly && !!saveAction && !!employeeFieldConfig}
            flexLayout
            onSubmit={handleSubmit}
            onCancel={handleBeforeCancel}
        >
            {({ getFieldDecorator, getFieldValue }) => (
                <>
                    <FormItem
                        label="中文姓名"
                        normalComponent={() => (
                            <div className="multiLineText">{parsedFormData?.employeeName || '--'}</div>
                        )}
                        editComponent={() =>
                            getFieldDecorator('employeeName', {
                                initialValue: parsedFormData?.employeeName ?? '',
                                rules: [
                                    { required: true, message: '请输入中文姓名' },
                                    {
                                        validator(rule, value, callback) {
                                            if (
                                                /[`~!#$%^&*()+=<>?:"{}|~！#￥%……&*（）={}|《》？：“”【】、；‘’，。、]/g.test(
                                                    value
                                                )
                                            ) {
                                                callback('不允许输入特殊字符');
                                            } else {
                                                callback();
                                            }
                                        }
                                    },
                                    {
                                        min: 2,
                                        max: 50,
                                        message: '中文姓名字数范围:2到50个字符'
                                    }
                                ]
                            })(<Input placeholder="请输入中文姓名" allowClear maxLength={100} />)
                        }
                    />
                    <FormItem
                        label="英文名"
                        normalComponent={() => (
                            <div className="multiLineText">{parsedFormData?.employeeEnglishName || '--'}</div>
                        )}
                        editComponent={() =>
                            getFieldDecorator('employeeEnglishName', {
                                initialValue: parsedFormData?.employeeEnglishName ?? '',
                                rules: [
                                    {
                                        validator(rule, value, callback) {
                                            if (
                                                /[`~!#$%^&*()+=<>?:"{}|~！#￥%……&*（）={}|《》？：“”【】、；‘’，。、]/g.test(
                                                    value
                                                )
                                            ) {
                                                callback('不允许输入特殊字符');
                                            } else {
                                                callback();
                                            }
                                        }
                                    },
                                    {
                                        min: 2,
                                        max: 50,
                                        message: '姓名字数范围:2到50个字符'
                                    }
                                ]
                            })(<Input placeholder="请输入英文名" allowClear minLength={2} maxLength={50} />)
                        }
                    />
                    <FormItem
                        label="证件类型"
                        show={currentEmployeeCountryCode === 'CN'}
                        normalComponent={() => (
                            <Text>{getIdCardTypeText(parsedFormData?.idCardType?.toString()) || '--'}</Text>
                        )}
                        editComponent={() =>
                            getFieldDecorator('idCardType', {
                                initialValue: parsedFormData?.idCardType?.toString() || undefined,
                                rules: [
                                    {
                                        required: true,
                                        message: '证件类型不能为空'
                                    }
                                ]
                            })(
                                <Select placeholder="请选择证件类型">
                                    {idCardTypeList?.map(item => (
                                        <Select.Option value={item.value} key={item.value}>
                                            {item.text}
                                        </Select.Option>
                                    ))}
                                </Select>
                            )
                        }
                    />
                    <FormItem
                        label="证件号码"
                        show={currentEmployeeCountryCode === 'CN'}
                        normalComponent={() => <div className="multiLineText">{parsedFormData?.idCard || '--'}</div>}
                        editComponent={() =>
                            getFieldDecorator('idCard', {
                                initialValue: parsedFormData?.idCard ?? undefined,
                                rules: [
                                    {
                                        required: true,
                                        message: '证件号码不能为空'
                                    },
                                    {
                                        validator(rule, value, callback) {
                                            const regex = /(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0[1-9]|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/;
                                            if (value && !regex.test(value)) {
                                                callback('请输入有效的证件号码（15位或18位数字或字母）');
                                            }
                                            callback();
                                        }
                                    }
                                ]
                            })(<Input placeholder="请输入证件号码" allowClear maxLength={50} />)
                        }
                    />
                    <FormItem
                        label="身份类型"
                        show={currentEmployeeCountryCode === 'SG'}
                        normalComponent={() => (
                            <Text>{getSingaporeIdTypeText(parsedFormData?.singaporeIdType) || '--'}</Text>
                        )}
                        editComponent={() =>
                            getFieldDecorator('singaporeIdType', {
                                initialValue: parsedFormData?.singaporeIdType || undefined,
                                rules: [
                                    {
                                        required: true,
                                        message: '身份类型不能为空'
                                    }
                                ]
                            })(
                                <Select placeholder="请选择身份类型">
                                    {singaporeIdTypeList?.map(item => (
                                        <Select.Option value={item.value} key={item.value}>
                                            {item.text}
                                        </Select.Option>
                                    ))}
                                </Select>
                            )
                        }
                    />
                    {getFormItemValue('singaporeIdType') === '1' && (
                        <FormItem
                            label="PR取得日期"
                            show={currentEmployeeCountryCode === 'SG'}
                            normalComponent={() => (
                                <span>
                                    {parsedFormData?.prAcquisitionDate === ''
                                        ? null
                                        : moment(parsedFormData?.prAcquisitionDate).format('YYYY-MM-DD')}
                                </span>
                            )}
                            editComponent={() =>
                                getFieldDecorator('prAcquisitionDate', {
                                    initialValue:
                                        parsedFormData?.prAcquisitionDate && parsedFormData?.prAcquisitionDate !== ''
                                            ? moment(parsedFormData?.prAcquisitionDate)
                                            : undefined,
                                    rules: [
                                        {
                                            required: true,
                                            message: 'PR取得日期不能为空'
                                        }
                                    ]
                                })(
                                    <DatePicker
                                        format="YYYY-MM-DD"
                                        style={{ width: '100%' }}
                                        placeholder="请选择PR取得日期"
                                    />
                                )
                            }
                        />
                    )}
                    {['1', '2'].includes(getFormItemValue('singaporeIdType')) && (
                        <FormItem
                            label="NRIC"
                            show={currentEmployeeCountryCode === 'SG'}
                            normalComponent={() => <div className="multiLineText">{parsedFormData?.nric || '--'}</div>}
                            editComponent={() =>
                                getFieldDecorator('nric', {
                                    initialValue: parsedFormData?.nric ?? undefined,
                                    rules: [
                                        {
                                            required: true,
                                            message: 'NRIC 不能为空'
                                        }
                                    ]
                                })(<Input placeholder="请输入NRIC" allowClear minLength={2} maxLength={50} />)
                            }
                        />
                    )}
                    {getFormItemValue('singaporeIdType') === '3' && (
                        <FormItem
                            label="FIN"
                            show={currentEmployeeCountryCode === 'SG'}
                            normalComponent={() => <div className="multiLineText">{parsedFormData?.fin || '--'}</div>}
                            editComponent={() =>
                                getFieldDecorator('fin', {
                                    initialValue: parsedFormData?.fin ?? undefined,
                                    rules: [
                                        {
                                            required: true,
                                            message: 'FIN 不能为空'
                                        }
                                    ]
                                })(<Input placeholder="请输入FIN" allowClear minLength={2} maxLength={50} />)
                            }
                        />
                    )}
                    <FormItem
                        label="种族"
                        show={currentEmployeeCountryCode === 'SG'}
                        normalComponent={() => (
                            <Text>{getSingaporeRaceText(parsedFormData?.singaporeRace) || '--'}</Text>
                        )}
                        editComponent={() =>
                            getFieldDecorator('singaporeRace', {
                                initialValue: parsedFormData?.singaporeRace || undefined,
                                rules: [
                                    {
                                        required: true,
                                        message: '种族不能为空'
                                    }
                                ]
                            })(
                                <Select placeholder="请选择种族">
                                    {singaporeRaceList?.map(item => (
                                        <Select.Option value={item.value} key={item.value}>
                                            {item.text}
                                        </Select.Option>
                                    ))}
                                </Select>
                            )
                        }
                    />
                    <FormItem
                        label="宗教信仰"
                        show={currentEmployeeCountryCode === 'SG'}
                        normalComponent={() => <Text>{getReligionText(parsedFormData?.religion) || '--'}</Text>}
                        editComponent={() =>
                            getFieldDecorator('religion', {
                                initialValue: parsedFormData?.religion || undefined,
                                rules: [
                                    {
                                        required: true,
                                        message: '宗教信仰不能为空'
                                    }
                                ]
                            })(
                                <Select placeholder="请选择宗教信仰">
                                    {religionList?.map(item => (
                                        <Select.Option value={item.value} key={item.value}>
                                            {item.text}
                                        </Select.Option>
                                    ))}
                                </Select>
                            )
                        }
                    />
                    <FormItem
                        label="出生日期"
                        normalComponent={() => (
                            <span>
                                {parsedFormData?.birthday === ''
                                    ? '--'
                                    : moment(parsedFormData?.birthday).format('YYYY-MM-DD')}
                            </span>
                        )}
                        editComponent={() =>
                            getFieldDecorator('birthday', {
                                initialValue:
                                    parsedFormData?.birthday && parsedFormData?.birthday !== ''
                                        ? moment(parsedFormData?.birthday)
                                        : undefined,
                                rules: [{ required: true, message: '出生日期不能为空' }]
                            })(
                                <DatePicker
                                    format="YYYY-MM-DD"
                                    style={{ width: '100%' }}
                                    placeholder="请选择出生日期"
                                />
                            )
                        }
                    />
                    <FormItem
                        label="出生地"
                        show={currentEmployeeCountryCode === 'SG'}
                        normalComponent={() => <Text>{parsedFormData?.birthplace?.replace(/[,]/g, '/') || '--'}</Text>}
                        editComponent={() =>
                            getFieldDecorator('birthplace', {
                                initialValue: parsedFormData?.birthplace
                                    ? restoreArrayLinkString(parsedFormData?.birthplace)
                                    : [],
                                rules: [{ required: true, message: '出生地不能为空' }]
                            })(<CityPicker valueType="array" showSearch placeholder="请选择出生地" />)
                        }
                    />
                    <FormItem
                        label="证件有效期"
                        show={currentEmployeeCountryCode === 'CN'}
                        normalComponent={() => <Text>{parsedFormData?.idCardExpiredDate || '--'}</Text>}
                        editComponent={() =>
                            getFieldDecorator('idCardExpiredDate', {
                                initialValue:
                                    parsedFormData?.idCardExpiredDate && parsedFormData?.idCardExpiredDate !== ''
                                        ? moment(parsedFormData?.idCardExpiredDate)
                                        : undefined,
                                rules: [
                                    {
                                        required: true,
                                        message: '证件有效期不能为空'
                                    }
                                ]
                            })(
                                <DatePicker
                                    format="YYYY-MM-DD"
                                    style={{ width: '100%' }}
                                    placeholder="请选择证件有效期"
                                />
                            )
                        }
                    />
                    <FormItem
                        label="性别"
                        normalComponent={() => <Text>{getSexTypeText(parsedFormData?.sex) || '--'}</Text>}
                        editComponent={() =>
                            getFieldDecorator('sex', {
                                initialValue: parsedFormData?.sex ?? undefined,
                                rules: [
                                    {
                                        required: true,
                                        message: '性别不能为空'
                                    }
                                ]
                            })(
                                <Radio.Group style={{ marginBottom: 0 }}>
                                    {sexTypeList?.map(item => (
                                        <Radio value={item.value} key={item.value}>
                                            {item.text}
                                        </Radio>
                                    ))}
                                </Radio.Group>
                            )
                        }
                    />
                    <FormItem
                        label="年龄"
                        normalComponent={() =>
                            moment(new Date()).diff(moment(getFormItemValue('birthday') || new Date()), 'year')
                        }
                        editComponent={() =>
                            moment(new Date()).diff(moment(getFieldValue('birthday') || new Date()), 'year')
                        }
                    />
                    <FormItem
                        label="民族"
                        show={currentEmployeeCountryCode === 'CN'}
                        normalComponent={() => (
                            <Text>{getPeopleNationalListText(parsedFormData?.peopleNational) || '--'}</Text>
                        )}
                        editComponent={() =>
                            getFieldDecorator('peopleNational', {
                                initialValue: parsedFormData?.peopleNational || undefined
                            })(
                                <Select placeholder="请选择民族">
                                    {peopleNationalList?.map(item => (
                                        <Select.Option value={item.value} key={item.value}>
                                            {item.text}
                                        </Select.Option>
                                    ))}
                                </Select>
                            )
                        }
                    />
                    <FormItem
                        label="参加工作时间"
                        normalComponent={() => (
                            <span>
                                {parsedFormData?.workStartDate === ''
                                    ? null
                                    : moment(parsedFormData?.workStartDate).format('YYYY-MM')}
                            </span>
                        )}
                        editComponent={() =>
                            getFieldDecorator('workStartDate', {
                                initialValue:
                                    parsedFormData?.workStartDate && parsedFormData?.workStartDate !== ''
                                        ? moment(parsedFormData?.workStartDate)
                                        : undefined,
                                rules: [{ required: true, message: '工作时间不能为空' }]
                            })(
                                <DatePicker.MonthPicker
                                    format="YYYY-MM"
                                    style={{ width: '100%' }}
                                    placeholder="请选择参加工作时间"
                                />
                            )
                        }
                    />
                    <FormItem
                        label="国籍"
                        normalComponent={() => <Text>{parsedFormData?.nation.replace(/[,]/g, '/') || '--'}</Text>}
                        editComponent={() =>
                            getFieldDecorator('nation', {
                                initialValue: parsedFormData?.nation
                                    ? restoreArrayLinkString(parsedFormData?.nation)
                                    : [],
                                rules: [{ required: true, message: '国籍不能为空' }]
                            })(
                                <CityPicker
                                    valueType="array"
                                    showSearch
                                    placeholder="请选择国籍"
                                    onChange={handleOnHouseHoldChange}
                                    filterAreaFn={areaData => {
                                        if (areaData?.[0] && areaData[0].code === '39') {
                                            delete areaData[0].children;
                                        }
                                        return areaData;
                                    }}
                                />
                            )
                        }
                    />
                    {getFormItemValue('idCardType') === '1' && showHousehold && (
                        <FormItem
                            label="户籍城市"
                            show={currentEmployeeCountryCode === 'CN'}
                            normalComponent={() => (
                                <Text>{parsedFormData?.nationalArea?.replace(/[,]/g, '/') || '--'}</Text>
                            )}
                            editComponent={() =>
                                getFieldDecorator('nationalArea', {
                                    initialValue: parsedFormData?.nationalArea
                                        ? restoreArrayLinkString(parsedFormData?.nationalArea)
                                        : []
                                })(
                                    <CityPicker
                                        valueType="array"
                                        showSearch
                                        placeholder="请选择户籍城市"
                                        filterAreaFn={areaData => areaData?.[0]?.children}
                                    />
                                )
                            }
                        />
                    )}
                    {getFormItemValue('idCardType')?.toString() === '1' && showHousehold && (
                        <FormItem
                            label="户籍类型"
                            show={currentEmployeeCountryCode === 'CN'}
                            normalComponent={() =>
                                firstHouseholdType && secondHouseholdType ? (
                                    <Text>
                                        {
                                            CENSUS_REGISTER_OPTIONS?.filter(v => v?.value === firstHouseholdType)[0]
                                                ?.label
                                        }
                                        /
                                        {
                                            HOUSEHOLD_TYPE_MAP[firstHouseholdType]?.filter(
                                                v => v?.value === secondHouseholdType
                                            )[0]?.text
                                        }
                                    </Text>
                                ) : (
                                    '--'
                                )
                            }
                            editComponent={() =>
                                getFieldDecorator('firstHouseholdType', {
                                    initialValue:
                                        firstHouseholdType !== '' && secondHouseholdType !== ''
                                            ? [firstHouseholdType, secondHouseholdType]
                                            : undefined
                                })(<Cascader placeholder="请选择户籍类型" options={CENSUS_REGISTER_OPTIONS} />)
                            }
                        />
                    )}
                    <FormItem
                        label="工龄"
                        normalComponent={() =>
                            moment(new Date()).diff(moment(getFormItemValue('workStartDate') || new Date()), 'year')
                        }
                        editComponent={() =>
                            moment(new Date()).diff(moment(getFieldValue('workStartDate') || new Date()), 'year')
                        }
                    />
                    {getFormItemValue('idCardType') === '1' && showHousehold && (
                        <FormItem
                            label="户籍地址"
                            show={currentEmployeeCountryCode === 'CN'}
                            normalComponent={() => (
                                <div className="multiLineText">{parsedFormData?.householdAddress || '--'}</div>
                            )}
                            editComponent={() =>
                                getFieldDecorator('householdAddress', {
                                    initialValue: parsedFormData?.householdAddress ?? undefined,
                                    rules: [
                                        {
                                            max: 200,
                                            message: '字数不能超过200个字符'
                                        }
                                    ]
                                })(<Input placeholder="请输入户籍地址" maxLength={200} allowClear />)
                            }
                        />
                    )}
                    <FormItem
                        label="政治面貌"
                        show={currentEmployeeCountryCode === 'CN'}
                        normalComponent={() => (
                            <Text>{getPoliticalLandscapeText(parsedFormData?.politicalLandscape) || '--'}</Text>
                        )}
                        editComponent={() =>
                            getFieldDecorator('politicalLandscape', {
                                initialValue: parsedFormData?.politicalLandscape || undefined,
                                rules: [
                                    {
                                        required: true,
                                        message: '政治面貌不能为空'
                                    }
                                ]
                            })(
                                <Select placeholder="请选择政治面貌">
                                    {politicalLandscapeList?.map(item => (
                                        <Select.Option value={item.value} key={item.value}>
                                            {item.text}
                                        </Select.Option>
                                    ))}
                                </Select>
                            )
                        }
                    />
                </>
            )}
        </FormContainer>
    );
};

// prop
PersonalInfoSection.propTypes = {
    formData: PropTypes.object.isRequired,
    onChange: PropTypes.func.isRequired,
    saveAction: PropTypes.func,
    readonly: PropTypes.bool
};

PersonalInfoSection.defaultProps = {
    saveAction: null,
    readonly: false
};

export default PersonalInfoSection;
